<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<div class="modal-dialog ms-modal-dialog" style="margin-top: 50px;">
	<div class="modal-content" style="width: 650px;">

		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
				aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<h4 class="modal-title">修改培训项目信息</h4>
		</div>
		<form class="form-horizontal ms-form form-personal-info" method="POST"
			action="${ctx.host}/project-data/${project.id}" data-validate="true">
			<input type="hidden" name='maxPhaseCount' id="maxPhaseCount"
				value="${project.phaseCount}" />
			<div id="phaseDateDivHid" style="display: none">
				<c:forEach items="${projectPhases }" var="projectPhase"
					varStatus="status">
					<input type='hidden' name='phaseBeginDateHid_${status.index+1}'
						id='phaseBeginDateHid_${status.index+1}'
						value='<fmt:formatDate value="${projectPhase.beginDate}" pattern="yyyy-MM-dd"/>' />
					<input type='hidden' name='phaseEndDateHid_${status.index+1}'
						id='phaseEndDateHid_${status.index+1}'
						value='<fmt:formatDate value="${projectPhase.endDate}" pattern="yyyy-MM-dd"/>' />
				</c:forEach>
			</div>

			<input type="hidden" name="_method" value="PATCH" /> <input
				type="hidden" name="projectId" value="${project.id}" />

			<div class="modal-body">

				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span
						class="text-red">*</span>编号：</label>
					<div class="col-xs-8 pull-left">
						<p class="form-control-static">${project.code}</p>
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span
						class="text-red">*</span>一级分类：</label>
					<div class="col-xs-8 pull-left">
						<select class="select2 form-control" name="firstCategoryId"
							data-validate="required" tabindex="2">
							<c:forEach items="${persist.trainingCategories}"
								var="TrainingCategory">
								<option></option>
								<option value="${TrainingCategory.id}"
									${TrainingCategory.id == project.firstCategory.id ? 'selected' : ''}>${TrainingCategory.name}</option>
							</c:forEach>
						</select>
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span
						class="text-red">*</span>二级分类：</label>
					<div class="col-xs-8 pull-left">
						<input class="select2 form-control" name="secondCategoryId"
							data-validate="required" tabindex="3"
							data-text="${project.secondCategory.id}" />
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span
						class="text-red">*</span>项目名称：</label>
					<div class="col-xs-8">
						<input type="text" class="form-control" name="name"
							value="${project.name}" placeholder="项目名称"
							data-validate="required" autocomplete="off" tabindex="2" />
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3"><span
						class="text-red">*</span>总期数：</label>
					<div class="col-xs-8">
						<input type="text" class="form-control" name="phaseCount"
							id="phaseCount" value="${project.phaseCount}" placeholder="总期数"
							data-validate="required"
							autocomplete="off" tabindex="3" />
					</div>
				</div>
				<div class="form-group  ms-form-group">
					<label class="control-label col-xs-3">原项目负责人：</label>
					<div class="col-xs-8 pull-left">
						<p class="form-control-static">${idmUser.usercn}&nbsp;-&nbsp;${idmUser.mail}
						<input type="hidden" name="projectLead" value="${project.projectLead}" />
            <a class="edit-lead">修改</a>
						</p>
					</div>
				</div>
				<div class="form-group  ms-form-group new-lead hide">
					<label class="control-label col-xs-3"><span
						class="text-red">*</span>新项目负责人：</label>
					<div class="col-xs-8 pull-left">
					  <input class="select2 form-control" name="projectLeadSelect" id="projectLead" tabindex="7" placeholder="不更改项目负责人请勿选择">
					</div>
				</div>
				<c:if test="${currentPrincipal.departmentId == null}">
					<div class="form-group  ms-form-group">
						<label class="control-label col-xs-3"><span
							class="text-red">*</span>事业部：</label>
						<div class="col-xs-8 pull-left">
							<select class="select2 form-control" name="departmentId"
								data-validate="required" id="selDepartment" tabindex="7">
								<c:forEach items="${persist.deparments}" var="department">
									<option></option>
                                    <c:if test="${department.name != '业务系统账户'}">
                                       <option value="${department.id}"
										${department.id == project.department.id ? 'selected' : ''}>${department.name}</option>
                                     </c:if>
								</c:forEach>
							</select>
						</div>
					</div>
				</c:if>
				<c:if test="${currentPrincipal.departmentId != null}">
					<div class="form-group  ms-form-group">
						<label class="control-label col-xs-3"><span
							class="text-red">*</span>事业部：</label>
						<p class="form-control-static">${persist.organize(currentPrincipal.departmentId).name}</p>
					</div>
				</c:if>

			</div>

			<div class="modal-footer">
				<button type="submit"
					class="btn btn-shadow-success btn-shadow umu-btn">确定</button>
				<button type="button"
					class="btn btn-shadow-default btn-shadow umu-btn"
					data-dismiss="modal">取消</button>
			</div>
		</form>

	</div>
</div>
<script type="text/javascript">
 
 $(document).ready(function() {
	
		$('select[name="departmentId"]').select2({
			theme: "classic",
		    placeholder : '请选择事业部',
		    minimumResultsForSearch : 1,
		    allowClear : true
        });
      
		$('#projectLead').select2({
		 placeholder : '不更改请勿选择',
         minimumResultsForSearch : 1,
         minimumInputLength: 2,
         allowClear : true,
         ajax: {
             type:'GET',
             url: function(params){      
                 return window.__CTX__.root + '/trainees/select-search?query='+ params
             },
             dataType: 'json',
             delay: 1500,
             results: function (response, page, i) {
               
               if(response.code == '0' || response.code == 0) {
            	   return {results: response.data.trainees}
               } else {
            	   return null;
               }
             },
             cache: true
         },
       }).on("change", function(e) {
          var selectLead = $("input[name='projectLeadSelect']").val();
          $("input[name='projectLead']").val(selectLead)
       })
       
       $(".edit-lead").click(function() {
    	   $(".new-lead").removeClass("hide");
       })
      
 })
</script>